<?php
/**
 *系统类的一些控制器
 */
namespace app\admin\controller;
use think\Request; 
use app\common\controller\ShopService as ShopService;
/**
 *创建时间: 2017-8-4
 *
 *系统模块控制器        
 */
class System extends BaseController
{
    /**
     * shop设置
     * 
     */
    public function index()
    {
       
        return view("shopInfo");
    }
    /**
     * 友情链接
     * 
     */
    public function links(){
    	$this->assign('linksList',$this->shopServ->getFriendLinks());
    	return view("shopLinks");
    }
    /*
    *添加友情链接
    *
    */
    public function linksAdd(Request $request){
    	if($request->isPost()){
    		$insetArr=$request->param();
    		$res = $this->shopServ->addFriendLinks($insetArr);
    		if($res){
    			$this->success('数据'.$res->link_name.'添加成功');
    		}else{
    			$this->error('失败');
    		}
    	}    	
    	return view("shopLinksAdd");
    }
    /**
     * 友情链接编辑
     * 
     */
    public function linksEdit(Request $request){
    	$id=$request->param('id');
    	// if(Request::instance()->isPost()){
    	// 	$postArr=$request->post();
    	// 	$res=$this->shopServ->updateFriendLinks($id,$postArr);
    	// }
    	if(Request::instance()->isAjax()){
    		$id=$request->param('id');
    		$postArr['link_name']=$request->param('link_name');
    		$postArr['link_url']=$request->param('link_url');
    		$postArr['orderby']=$request->param('orderby');
    		$postArr['is_show']=$request->param('is_show');
    		$postArr['target']=$request->param('target');    		     
    		$res=$this->shopServ->updateFriendLinks($id,$postArr);
    		return $res;
    	}
    	$linksInfoItem=$this->shopServ->getFriendLinks($id);
    	$this->assign('linksInfo',$linksInfoItem);
    	return view("shopLinksEdit");
    }
     /**
     * 友情链接删除 
     * get id del
     * return 1 or 0
     */
     public function linksDel($id=''){
     	if($id){
     		return $this->shopServ->delFriendLinks($id);
     	}else{
     		return 0;
     	}
     }
}